/**
 * 
 */
package leetCode;

/**输入数组是否能只改变一个元素编程非降序数列
 * @author zhongfang
 *
 */
public class NonDecreaseArray {
    public boolean checkPossibility(int[] nums) {
    	int last1=Integer.MIN_VALUE,last2=Integer.MIN_VALUE;
    	int minChance=1;
    	for (int i = 0; i < nums.length; i++) {
			if(nums[i]<last1){//出现逆序
				if(minChance==0){
					return false;
				}
				if(last2<=nums[i]){//如果再前面的数都能满足，则修改i-1
					nums[i-1]=last2;
				}else {//修改i
					nums[i]=last1;
				}
				minChance--;
			}
			last1=nums[i];
			last2=i==0?Integer.MIN_VALUE:nums[i-1];
		}
        return true;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
